Apply attributes to a file

The following example demonstrates the GetAttributes and SetAttributes methods by applying the Archive and Hidden attributes to a file

C# .NET

public static String DoTest()
{
         string strRet = "";
         string path = @"c:\temp\MyTest.txt";
         // Delete the file if it exists.
         if (!File.Exists(path))
         {
                  File.Create(path);
         }

         if ((File.GetAttributes(path) & FileAttributes.Hidden) == FileAttributes.Hidden)
         {
                  // Show the file.
                  File.SetAttributes(path, FileAttributes.Archive);
                  strRet = String.Format("The {0} file is no longer hidden.", path);
         }
         else
         {
                  // Hide the file.
                  File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
                  strRet = String.Format("The {0} file is now hidden.", path);
         }

         return strRet;         
}

 

Blaze++ .NET

static String DoTest()
{
         String strRet = "";
         String path = "c:\\temp\\MyTest.txt";
         // Delete the file if it exists.
         if (!File::Exists(path))
         {
                  File::Create(path);
         }

         if ((File::GetAttributes(path) & FileAttributes::Hidden) == FileAttributes::Hidden)
         {
                  // Show the file.
                  File::SetAttributes(path, FileAttributes::Archive);
                  strRet = String::Format("The {0} file is no longer hidden.", path);
         }
         else
         {
                  // Hide the file.
                  File::SetAttributes(path, File::GetAttributes(path) | FileAttributes::Hidden);
                  strRet = String::Format("The {0} file is now hidden.", path);
         }

         return strRet;         
}